package com.iafme.service.impl;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iafme.dto.req.CollegesReqDTO;
import com.iafme.dto.res.CollegesResDTO;
import com.iafme.mapper.CollegesMapper;
import com.iafme.model.Colleges;
import com.iafme.service.CollegesService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author summer
 * @version 1.0
 * @date 2025/2/19 21:27
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class CollegesServiceImpl extends ServiceImpl<CollegesMapper, Colleges> implements CollegesService {
    @Override
    public Page<CollegesResDTO> lists(CollegesReqDTO collegesReqDTO) {
        Page<Colleges> page=new Page<>(collegesReqDTO.getPageNum(),collegesReqDTO.getPageSize());
        LambdaQueryWrapper<Colleges> like = Wrappers.lambdaQuery(Colleges.class).
                like(StrUtil.isNotEmpty(collegesReqDTO.getName()), Colleges::getName, collegesReqDTO.getName())
                .orderByDesc(Colleges::getCreateTime);
        return Convert.convert(new TypeReference<Page<CollegesResDTO>>() {
        },this.page(page,like));
    }
}
